<?php 

require_once('getconfig.php');

Class Model_Admin extends Dbo_DbManager
 {

	protected $admin_id;
	protected $c_admin_user;
	protected $c_admin_password;

    public function __construct($createCon=TRUE){
 	  parent::__construct($createCon);
 	}
	public function getuserid()
	{
		return  $this->admin_id;
	}
	public function getusername()
	{
		return  $this->c_admin_user;
	}
	public function getpassword()
	{
		return  $this->c_admin_password;
	}

	public function setuserid($admin_id)
	{
		$this->admin_id=$admin_id;
	}

	public function setusername($c_admin_user)
	{
		$this->c_admin_user=$c_admin_user;
	}
	public function setpassword($c_admin_password)
	{
		$this->c_admin_password=$c_admin_password;
	}
	

	public function write()
	{
		$objDbManager = new Dbo_DbManager();
		return $objDbManager->write($this,FALSE);
	}

	public static function delete($admin_id)
	{
		$objDbManager = new Dbo_DbManager();
		return $objDbManager->remove($admin_id,__CLASS__);
	}


	public static function get($admin_id=NULL)
	{
		$arrRes=array();
		$objDbManager = new Dbo_DbManager();
		$arrModel_Admin = $objDbManager->fetch(array('admin_id' => $admin_id),__CLASS__);
		if(count($arrModel_Admin)>0) {
			foreach($arrModel_Admin as $arrNew) { 
				$objUser = self::build($arrNew);
				$arrRes[]=$objUser;
			}
		}
		return $arrRes;
	}


	public function getoncondition()
	{
		$arrRes=array();
		$objDbManager = new Dbo_DbManager();
		$arrModel_Admin = $objDbManager->fetchOnCondition($this,TRUE);
		if(count($arrModel_Admin)>0) {
			foreach($arrModel_Admin as $arrNew) { 
				$objUser = self::build($arrNew);
				$arrRes[]=$objUser;
			}
		}
		return $arrRes;
	}


	public static function build(array $arrModel_Admin)
	{
		$objModel_Admin = new Model_Admin(FALSE);
		@$objModel_Admin->setuserid($arrModel_Admin['admin_id']);
		@$objModel_Admin->setusername($arrModel_Admin['c_admin_user']);
		@$objModel_Admin->setpassword($arrModel_Admin['c_admin_password']);
		return $objModel_Admin;
 	 }
     public function getlastinsertedid(){
		$objDbManager = new Dbo_DbManager ();
		$userid=$objDbManager->getMaxId($this,"max","admin_id");
		return $userid;
	}
	
	public static function checkUser($strusername,$strpassword){
	
		$arrRes=array();
		$objDbManager = new Dbo_DbManager ();
		$qry="select * from admin where c_admin_user='$strusername' and c_admin_password='$strpassword'";
		$arrModel_Admin=$objDbManager->runquery("$qry");
		if (count( $arrModel_Admin ) > 0) {
			foreach ( $arrModel_Admin as $arrNew ) {
				$objUser = self::build ( $arrNew );
				$arrRes [] = $objUser;
			}
		}
		return $arrRes;
	}
	
	
	
    public  function __call($method, $arguments) {
    	
       if(count($arguments)>0){
       	   $sqlFunction=$arguments[0];
       	    $objDbManager = new Dbo_DbManager();
       	   return $objDbManager->runSqlFunctions(__CLASS__,array($method=>$sqlFunction));
       }
    }
 
	

 }
 ?>
